var BelleNuitParser = function() {			
};
BelleNuitParser.prototype = {
	/**
	 * Creates an array containing a {time_in, time_out, text} object for each subtitle line. 
	 */
	parse: function(string) {
		var result = [];  
		var line_blocks = string.split('\n');
		var last_line = line_blocks[line_blocks.length-1];
		var o = {}; 
		$(line_blocks).each(function(i,line) { 
			var is_first_line = line.indexOf('/tc')!=-1;
			var is_text_line = !is_first_line &&  line != '' && line.substr(0,1) != '/';
			var is_empty_line = line == '';
			var is_last_block_line = line_blocks[i+1] && line_blocks[i+1].indexOf('/tc')!=-1;
			var is_last_total_line = i === line_blocks.length-1;
			var line_parts = line.split(' ');
			if (is_first_line) {
				o = {
					time_in: line_parts[1],
					time_out: line_parts[2]
				}
			}
			if (is_text_line) {
				o.text = o.text ? o.text + '\n' + line  : line;
			}  
			if ((is_empty_line && !is_last_block_line) && !is_last_total_line) {
				alert('empty text line at '+o.time_in+' '+o.time_out+' (line '+(result.length+1)+')')
			}
			if ( is_last_block_line || is_last_total_line) {
				result.push( o );
			}
		}); 
		return result;
	}
}